package com.thread.thread.FutureTask;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;
import java.util.concurrent.atomic.AtomicInteger;

public class FutureTaskTest  {
	static ExecutorService executorService= Executors.newFixedThreadPool(10);
	public static void main(String[] args) throws  Exception{
		AtomicInteger atomicInteger=new AtomicInteger(0);

		Callable<String> callable=new Callable<String>() {
			@Override
			public String call() throws Exception {
				return "菜菜"+atomicInteger.incrementAndGet();
			}
		};

		FutureTask<String> stringFutureTask1=new FutureTask<>(callable);

		new Thread(stringFutureTask1).start();


		FutureTask<String> stringFutureTask2=new FutureTask<>(callable);

		new Thread(stringFutureTask2).start();


		System.out.println(stringFutureTask1.get());
		System.out.println(stringFutureTask2.get());


		Future<?> submit = executorService.submit(stringFutureTask1,3);
		executorService.submit(stringFutureTask2);
		System.out.println(submit.get());
		System.out.println(stringFutureTask1.get());
		System.out.println(stringFutureTask2.get());

		//测试结果菜菜1 菜菜2   菜菜2 菜菜1 都有可能



 	}
}
